What is vscode-languageserver-textdocument?
The vscode-languageserver-textdocument package is designed to provide support for creating and managing text documents in language servers that are compatible with the Language Server Protocol (LSP). This package is particularly useful for developers building extensions for code editors like Visual Studio Code, enabling them to handle text document manipulations and updates efficiently.
Text Document Creation
This feature allows the creation of a new text document. The 'create' method takes parameters such as URI, language identifier, version number, and the initial text content of the document.
const { TextDocument } = require('vscode-languageserver-textdocument');
const textDocument = TextDocument.create('uri', 'languageId', 1, 'Initial content of the document.');
Text Document Update
This feature supports updating the content of an existing text document. The 'update' method is used to apply changes to the document, where changes are described in terms of text ranges and new text, and the document version is incremented.
const { TextDocument } = require('vscode-languageserver-textdocument');
const textDocument = TextDocument.create('uri', 'languageId', 1, 'Initial content');
const changes = [{ range: { start: { line: 0, character: 0 }, end: { line: 0, character: 13 } }, text: 'Updated content' }];
textDocument.update(changes, 2);